<template>
  <tl-sub-page :render="render" :visible.sync="visible" v-dialogDrag :title="title" :close-on-click-modal="false" class="tl-dialog" width="1200px" @open="open" @close="close">
    <el-form class="tl-form" ref="dealform" :model="model" :rules="rules" label-width="120px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="收据号码" prop="receiptcode" :rules="rules.validateRequire">
            <el-input v-model="model.receiptcode"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="收据日期" prop="receiptdate">
            <el-date-picker v-model="model.receiptdate" type="date" placeholder="收据日期" value-format="yyyy-MM-dd"></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="收据金额" prop="receiptmoney" :rules="rules.validateRequire">
            <el-input-number v-model="model.receiptmoney" controls-position="right" :step="1" :min="0" style="width:95%"></el-input-number>
            <span>元</span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="实际收据日期" prop="actualreceiptdate" :rules="rules.validateRequire">
            <el-date-picker v-model="model.actualreceiptdate" type="date" placeholder="实际收据日期" value-format="yyyy-MM-dd"></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="是否邮寄" prop="ismail" v-if="isAddAndReadd" :rules="isAddAndReadd ? rules.validateRequire : { required: false }">
            <el-select v-model="model.ismail" filterable clearable @change="changeIsMail">
              <el-option v-for="item in codeModel.ismailList" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="寄出日期" prop="maildate" v-if="model.ismail==='0'">
            <el-date-picker v-model="model.maildate" type="date" placeholder="寄出日期" value-format="yyyy-MM-dd"></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="快递单号" prop="couriernumber" v-if="model.ismail==='0'">
            <el-input v-model="model.couriernumber"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="快递方式" prop="courier" v-if="model.ismail==='0'">
            <el-select v-model="model.courier" filterable clearable>
              <el-option v-for="item in codeModel.courierList" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="收件人" prop="receiver" :rules="rules.validateRequire" v-if="model.ismail==='0'">
            <el-input v-model="model.receiver"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="收件人手机号" prop="receivertel" v-if="model.ismail==='0'">
            <el-input v-model="model.receivertel"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="收件人固定电话" prop="receiverfixedtel" v-if="model.ismail==='0'">
            <el-input v-model="model.receiverfixedtel"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="邮寄地址" prop="mailaddress" :rules="rules.validateRequire" v-if="model.ismail==='0'">
            <el-input v-model="model.mailaddress"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="120px" :disabled="disableEditSubmit || disableSave">
      <el-row>
        <el-col :span="24">
          <el-divider content-position="center"><span>【以下信息为只读信息】</span></el-divider>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-divider content-position="left"><span>【项目】相关信息</span></el-divider>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="项目" prop="projectid" :required="true" :rules="rules.validateRequire">
            <el-input v-model="model.dispprojectid" :disabled="true" class="tl-ref-selector">
              <el-button slot="append" type="primary" icon="el-icon-search" @click="openpmProjectRefDialog" v-if="!disableEditSubmit && !disableSave"></el-button>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="项目编号">
            <el-input v-model="model.projectcode" :disabled="true"> </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="合同金额">
            <el-input-number v-model="model.projectcontractmoney" controls-position="right" :step="1" :precision="2" style="width:95%" :disabled="true"></el-input-number>
            <span>元</span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="项目金额">
            <el-input-number v-model="model.projectmoney" controls-position="right" :step="1" :min="0" :precision="2" style="width:95%" :disabled="true"></el-input-number>
            <span>元</span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="收据总金额">
            <el-input-number v-model="model.projectreceiptmoney" controls-position="right" :step="1" :precision="2" style="width:95%" :disabled="true"></el-input-number>
            <span>元</span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="已收款金额">
            <el-input-number v-model="model.projectrecbillmoney" controls-position="right" :step="1" :min="0" :precision="2" style="width:95%" :disabled="true"></el-input-number>
            <span>元</span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-divider content-position="left"><span>【业务类型】相关信息</span></el-divider>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="业务类型" prop="category" :rules="rules.validateRequire">
            <el-select v-model="model.category" filterable clearable>
              <el-option v-for="item in codeModel.categoryList" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="原收据号" prop="oldreceiptcode">
            <el-input v-model="model.oldreceiptcode"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form class="tl-form" ref="categoryform" :model="model" :rules="rules" label-width="120px" v-show="isCancelAndReadd" :disabled="disableEditSubmit || disableSave">
        <el-row>
          <el-col :span="12">
            <el-form-item label="原收据邮寄单号" prop="oldexpressno">
              <el-input v-model="model.oldexpressno"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="原客户名称" prop="oldcustomer" v-show="isCancelAndReadd">
              <el-input v-model="model.oldcustomer"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="原收据日期" prop="oldreceiptdate">
              <el-date-picker v-model="model.oldreceiptdate" type="date" placeholder="原开票日期" value-format="yyyy-MM-dd"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="原收据金额" prop="oldreceiptmoney">
              <el-input-number v-model="model.oldreceiptmoney" controls-position="right" :step="1" :min="0" style="width:95%"></el-input-number>
              <span>元</span>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-row>
        <el-col :span="24" v-show="model.category == '3'">
          <el-form-item label="重开原因" prop="rereceiptreason">
            <el-input v-model="model.rereceiptreason" type="textarea" :rows="2"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24" v-show="model.category == '2'">
          <el-form-item label="作废原因" prop="cancelreason">
            <el-input v-model="model.cancelreason" type="textarea" :rows="2"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form class="tl-form" ref="receiptform" :model="model" :rules="rules" label-width="120px" v-show="isAddAndReadd" :disabled="disableEditSubmit || disableSave">
        <el-row>
          <el-col :span="24">
            <el-divider content-position="left"><span>【收据】相关信息</span></el-divider>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="收据开具组织" prop="receiptorgname">
              <tl-ref-org v-model="model.receiptorgname" :initDisplayData.sync="model.receiptorgname" dataType="code" :singleSelect="true" @confirm="onSelectOrg" :disabled="disableEditSubmit || disableSave"></tl-ref-org>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="收据所属部门" prop="receiptdeptname" :required="true">
              <tl-ref-dept v-model="model.receiptdeptname" :initDisplayData.sync="model.receiptdeptname" dataType="code" nameType="fullname" :singleSelect="true" @confirm="onSelectDept" :disabled="disableEditSubmit || disableSave" :externalQueryParam="{qry_enabled:1}"></tl-ref-dept>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="收据日期类型" prop="receiptdatetype">
              <el-select v-model="model.receiptdatetype" filterable clearable @change="currentReceiptDate">
                <el-option v-for="item in codeModel.receiptdatetypeList" :key="item.code" :label="item.name" :value="item.code" />
              </el-select>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
                        <el-form-item label="收据日期" prop="receiptdate">
                            <el-date-picker v-model="model.receiptdate" type="date" placeholder="收据日期" value-format="yyyy-MM-dd"></el-date-picker>
                        </el-form-item>
                    </el-col> -->
        </el-row>
        <!-- <el-row>
                    <el-col :span="12">
                        <el-form-item label="收据金额" prop="receiptmoney">
                            <el-input-number v-model="model.receiptmoney" controls-position="right" :step="1" :min="0" style="width:95%"></el-input-number>
                            <span>元</span>
                        </el-form-item>
                    </el-col>
                </el-row> -->
        <el-row>
          <el-col :span="24">
            <el-form-item label="收据填写要求" prop="demand">
              <el-input v-model="model.demand" type="textarea" :rows="2"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="收据说明" prop="explain">
              <el-input v-model="model.explain" type="textarea" :rows="2"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="客户名称" prop="customername" :required="true">
              <el-input v-model="model.customername" :disabled="true" class="tl-ref-selector">
                <el-button slot="append" type="primary" icon="el-icon-search" @click="openpmCustomerRefDialog" v-if="!disableEditSubmit && !disableSave"></el-button>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="企业名称" prop="companyname">
              <el-input v-model="model.companyname" :disabled="true" class="tl-ref-selector">
                <el-button slot="append" type="primary" icon="el-icon-search" @click="openpmCustomerBillRefDialog" v-if="!disableEditSubmit && !disableSave"></el-button>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="企业地址" prop="companyaddress">
              <el-input v-model="model.companyaddress" :readonly="true" class="is-disabled"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="收件人性质" prop="receivertype">
              <el-select v-model="model.receivertype" filterable clearable>
                <el-option v-for="item in codeModel.receivertypeList" :key="item.code" :label="item.name" :value="item.code" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- <el-row>
                    <el-col :span="12">
                        <el-form-item label="收件人" prop="receiver">
                            <el-input v-model="model.receiver"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="收件人电话" prop="receivertel">
                            <el-input v-model="model.receivertel"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="邮寄地址" prop="mailaddress">
                            <el-input v-model="model.mailaddress"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row> -->
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="description">
              <el-input v-model="model.description" type="textarea" :rows="2"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <!-- <el-form class="tl-form" ref="dealform" :model="model" :rules="rules" label-width="150px" v-show="model.state == '9'" :disabled="disableEditSubmit || disableSave">
                            <el-row>
                                <el-col :span="24">
                                    <el-divider content-position="left"><span>【收据邮寄】相关信息</span></el-divider>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="收据号码" prop="receiptcode">
                                        <el-input v-model="model.receiptcode"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="签收单是否返回" prop="isreceiptreturn">
                                        <el-select v-model="model.isreceiptreturn" filterable clearable>
                                            <el-option v-for="item in codeModel.isreceiptreturnList" :key="item.code" :label="item.name" :value="item.code" />
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="快递单号" prop="couriernumber">
                                        <el-input v-model="model.couriernumber"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="快递方式" prop="courier">
                                        <el-select v-model="model.courier" filterable clearable>
                                            <el-option v-for="item in codeModel.courierList" :key="item.code" :label="item.name" :value="item.code" />
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="实际收据日期" prop="actualreceiptdate">
                                        <el-date-picker v-model="model.actualreceiptdate" type="date" placeholder="实际收据日期" value-format="yyyy-MM-dd"></el-date-picker>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="寄出日期" prop="maildate">
                                        <el-date-picker v-model="model.maildate" type="date" placeholder="寄出日期" value-format="yyyy-MM-dd"></el-date-picker>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                        </el-form> -->
      <el-collapse>
        <el-collapse-item title="【单据】相关信息">
          <el-row>
            <el-col :span="12">
              <el-form-item label="申请部门" prop="deptname">
                <tl-ref-dept v-model="model.deptcode" :initDisplayData.sync="model.deptname" :disabled="true" dataType="code" nameType="fullname" :singleSelect="true" :externalQueryParam="{qry_enabled:1}"></tl-ref-dept>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="申请公司" prop="orgname">
                <el-input v-model="model.orgname" :readonly="true" class="is-disabled"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="申请人" prop="username">
                <tl-ref-user v-model="model.username" :initDisplayData.sync="model.username" :disabled="true" dataType="code" :singleSelect="true"></tl-ref-user>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="申请人工号" prop="usercode">
                <el-input v-model="model.usercode" :readonly="true" class="is-disabled"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="单据日期" prop="docdate" :rules="rules.validateRequire">
                <el-date-picker v-model="model.docdate" type="date" placeholder="单据日期" value-format="yyyy-MM-dd"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="提交时间" prop="submitdate">
                <el-date-picker v-model="model.submitdate" type="datetime" placeholder="提交时间" disabled></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="审批流程" prop="flowid">
                <el-input v-model="model.dispflowid" :readonly="true" class="is-disabled"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="状态" prop="state">
                <el-input v-model="model.dispstate" disabled></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
      </el-collapse>
    </el-form>
    <tl-approval-history ref="history" sourceType="PmReceiptApply" :sourceId="model.id" />
    <div slot="footer" class="dialog-footer">
      <el-button :type="disableEditSubmit === false ? 'text' : 'primary'" @click="doCancelEdit" v-if="uiOperateState<=2">取消</el-button>
      <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="!disableEditSubmit" :disabled="disableSave">
        <svg-icon icon-class="save" />保存
      </el-button>
      <el-button type="primary" @click="doSubmitApproval" :loading="submitLoading" v-if="!disableEditSubmit" :disabled="disableApproval">
        <svg-icon icon-class="send" />提交审批
      </el-button>
      <tl-attachment sourceType="PmReceiptApply" :sourceId="model.id" :disabled="disableAttachment" :editable="stateEdit"></tl-attachment>
      <el-button type="primary" @click="$refs.history.visible = true" :disabled="disableApprovalHistory">
        <svg-icon icon-class="list" />审批历史
      </el-button>
      <el-button type="primary" @click="doDelApproval" :loading="delApprovalLoading" v-if="!disableEditSubmit" :disabled="disableDelApproval">
        <svg-icon icon-class="undo" />取消审批
      </el-button>
    </div>
    <tlpm-project-ref ref="pmProjectRef" @confirm="getpmProjectRefData" :isSingleSelect="true"></tlpm-project-ref>
    <tlpm-customer-ref ref="pmCustomerRef" @confirm="getpmCustomerRefData" :isSingleSelect="true"></tlpm-customer-ref>
    <tlpm-customer-bill-ref ref="pmCustomerBillRef" @confirm="getpmCustomerBillRefData" :isSingleSelect="true" :externalQueryParam="{qry_customerid:model.customerid}"></tlpm-customer-bill-ref>
  </tl-sub-page>
</template>

<script>
/** mixins */
import { mixin_approval_edit } from '@tapui/mixins/mixin_approval_edit'
/** 子组件 */
import tlpmProjectRef from '@/views/ProjectManage/pmProject/refList.vue'
import tlpmCustomerRef from '@/views/ProjectManage/pmCustomer/refList.vue'
import tlpmCustomerBillRef from '@/views/ProjectManage/pmCustomerBill/refList.vue'
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
/** VUE配置 */
export default {
  mixins: [mixin_approval_edit],
  components: { tlpmProjectRef, tlpmCustomerRef, tlpmCustomerBillRef },
  data() {
    return {
      moduleTitle: '项目收据申请',
      urlPrefix: '/pm/receiptApply/',
      url: {
        // 额外的url
      }
    }
  },
  computed: {
    // 状态为新增或重开
    isAddAndReadd() {
      return this.model.category === '1' || this.model.category === '3'
    },
    // 状态为作废或重开
    isCancelAndReadd() {
      return this.model.category === '2' || this.model.category === '3'
    }
  },
  methods: {
    assignDefaultValue() {
      if (this.isAdd) {
        if (this.codeModel.flowidList && this.codeModel.flowidList.length > 0) {
          this.$set(this.model, 'flowid', parseInt(this.codeModel.flowidList[0].id))
        }
        this.$set(this.model, 'orgcode', this.org.code)
        this.$set(this.model, 'orgname', this.org.name)
        this.$set(this.model, 'deptcode', this.dept.code)
        this.$set(this.model, 'deptname', this.dept.fullname)
        this.$set(this.model, 'usercode', this.user.code)
        this.$set(this.model, 'username', this.user.name)
        this.$set(this.model, 'docdate', new Date())
        // 1 客户， 2 鼎信员工
        this.$set(this.model, 'receivertype', '1')
      }
    },
    loaded() {
      // 页面加载完毕执行
      if (!this.isAdd && this.model.docno) {
        this.title = this.title + `（单据编号：${this.model.docno}）`
      }
      let { actualreceiptdate, maildate, receivertype } = this.model
      if (!actualreceiptdate) {
        actualreceiptdate = new Date()
      }
      if (!maildate) {
        maildate = new Date()
      }
      this.$set(this.model, 'actualreceiptdate', actualreceiptdate)
      this.$set(this.model, 'maildate', maildate)
      // 当收件人性质是“鼎信员工(2)”时，则默认“签收单是否返回”为是(1)；当收件人性质是“客户(1)”时，则默认“签收单是否返回”为否(0)
      if (receivertype === '1') {
        this.$set(this.model, 'isreceiptreturn', '0')
      }
      if (receivertype === '2') {
        this.$set(this.model, 'isreceiptreturn', '1')
      }
    },
    onSelectDept(selectedDepts) {
      const selectedDept = selectedDepts[0]
      this.$set(this.model, 'receiptdeptname', selectedDept.fullname)
      this.$set(this.model, 'receiptdeptcode', selectedDept.code)
    },
    onSelectOrg(selectedOrgs) {
      const selectedOrg = selectedOrgs[0]
      this.$set(this.model, 'receiptorgname', selectedOrg.name)
      this.$set(this.model, 'receiptorgcode', selectedOrg.code)
    },
    /** 打开项目参照 */
    openpmProjectRefDialog() {
      this.$refs.pmProjectRef.visible = true
    },
    /** 获取项目参数数据 */
    getpmProjectRefData(selectionRow, selectKey, selectionValue) {
      this.$set(this.model, 'projectid', selectionRow.id)
      this.$set(this.model, 'dispprojectid', selectionRow.name)
      this.$set(this.model, 'receiptorgname', selectionRow.ownerorgname)
      this.$set(this.model, 'receiptorgcode', selectionRow.ownerorgcode)
      this.$set(this.model, 'receiptdeptname', selectionRow.ownerdeptname)
      this.$set(this.model, 'receiptdeptcode', selectionRow.ownerdeptcode)
      this.$set(this.model, 'projectcode', selectionRow.code)
      this.$set(this.model, 'projectcontractmoney', selectionRow.contractmoney)
      this.$set(this.model, 'projectmoney', selectionRow.projectmoney)
      this.$set(this.model, 'projectrecbillmoney', selectionRow.recbillmoney)
      this.$set(this.model, 'projectreceiptmoney', selectionRow.receiptmoney)
    },
    /** 打开客户名称参照 */
    openpmCustomerRefDialog() {
      this.$refs.pmCustomerRef.visible = true
    },
    /** 获取客户名称参数数据 */
    getpmCustomerRefData(selectionRow, selectKey, selectionValue) {
      this.$set(this.model, 'customerid', selectionRow.id)
      this.$set(this.model, 'customername', selectionRow.name)
      this.$set(this.model, 'companyname', '')
      this.$set(this.model, 'companyaddress', '')
      this.$set(this.model, 'receiver', '')
      this.$set(this.model, 'receivertel', '')
      this.$set(this.model, 'mailaddress', '')
    },
    /** 打开开票标识参照 */
    openpmCustomerBillRefDialog() {
      if (!this.model.customerid) {
        this.$message({
          message: '请先选择客户名称！',
          type: 'warning'
        })
        this.$refs.pmCustomerBillRef.visible = false
      } else {
        this.$refs.pmCustomerBillRef.visible = true
      }
    },
    /** 获取开票标识参数数据 */
    getpmCustomerBillRefData(selectionRow, selectKey, selectionValue) {
      this.$set(this.model, 'companyname', selectionRow.companyname)
      this.$set(this.model, 'companyaddress', selectionRow.companyaddress)
      this.$set(this.model, 'receiver', selectionRow.receiver)
      this.$set(this.model, 'receivertel', selectionRow.receivertel)
      this.$set(this.model, 'mailaddress', selectionRow.mailaddress)
    },
    saveCourierInfo(resolve, reject) {
      const {
        id,
        receiptcode,
        receiptmoney,
        receiptdate,
        maildate,
        ismail,
        receiver,
        receivertel,
        mailaddress,
        couriernumber,
        courier,
        actualreceiptdate,
        // isreceiptreturn,
        receiptdatetype
      } = this.model
      if (!receiptcode) {
        this.$tap.alert('请填写收据号码')
        reject()
      }
      if (!receiptmoney) {
        this.$tap.alert('请填写收据金额')
        reject()
      }
      // 收据日期类型为非 空着不填（2），则需填写收据日期
      if (receiptdatetype !== '2') {
        if (!receiptdate) {
          this.$tap.alert('请填写收据日期')
          reject()
        }
      }
      // 如果是否邮寄字段为是的话
      if (this.model.ismail === '0') {
        // if (!maildate) {
        //   this.$tap.alert('请填写寄出日期')
        //   reject()
        // }
        if (!receiver) {
          this.$tap.alert('请填写收件人')
          reject()
        }
        if (!receivertel) {
          this.$tap.alert('请填写收件人电话')
          reject()
        }
        if (!mailaddress) {
          this.$tap.alert('请填写邮寄地址')
          reject()
        }
        // if (!courier) {
        //   this.$tap.alert('请填写快递方式')
        //   reject()
        // }
        // if (!couriernumber) {
        //   this.$tap.alert('请填写快递单号')
        //   reject()
        // }
        if (this.model.receivertel === '' && this.model.receiverfixedtel === undefined) {
          this.$tap.alert('收件人手机号及收件人固定电话至少填写一个！', 'warning')
          reject()
        }
        if (this.model.receivertel === null && this.model.receiverfixedtel === null) {
          this.$tap.alert('收件人手机号及收件人固定电话至少填写一个！', 'warning')
          reject()
        }
        if (this.model.receivertel === '' && this.model.receiverfixedtel === '') {
          this.$tap.alert('收件人手机号及收件人固定电话至少填写一个！', 'warning')
          reject()
        }
        // 校验手机号的合法性
        var telphone = /^1[3456789]\d{9}$/
        if (this.model.receivertel.length !== 11 || !telphone.test(this.model.receivertel)) {
          this.$tap.alert('收件人手机号格式不合法，请重新输入！', 'warning')
          reject()
        }
        // 校验固定电话
        var fixedtel = /^([0-9]{3,4}-)?[0-9]{7,8}$/
        if (fixedtel.test(this.model.receiverfixedtel)) {
          this.$tap.alert('收件人固定电话格式不合法，请重新输入！', 'warning')
          reject()
        }
      }
      // 如果是否邮寄字段为否的话,清空数据
      if (this.model.ismail === '1') {
        this.$set(this.model, 'maildate', '')
        this.$set(this.model, 'couriernumber', '')
        this.$set(this.model, 'courier', '')
        this.$set(this.model, 'receiver', '')
        this.$set(this.model, 'receivertel', '')
        this.$set(this.model, 'receiverfixedtel', '')
        this.$set(this.model, 'mailaddress', '')
      }
      //   if (!isreceiptreturn) {
      //     this.$tap.alert('请填写签收单是否返回')
      //     reject()
      //   }
      if (!actualreceiptdate) {
        this.$tap.alert('请填写实际收据日期')
        reject()
      }
      const param = {
        id,
        receiptcode,
        receiptmoney,
        receiptdate,
        maildate,
        ismail,
        receiver,
        receivertel,
        mailaddress,
        couriernumber,
        courier,
        actualreceiptdate
        // isreceiptreturn
      }
      putAction(this.url.edit, param)
        .then(res => {
          if (res.success) {
            resolve()
          } else {
            this.$tap.alert(res.message, 'warning')
            reject()
          }
        })
        .catch(err => {
          this.$tap.alert('保存发票开具信息失败，请联系系统管理员', 'warning')
          reject()
        })
    }
  }
}
</script>

